<%@ page import="cn.school.entity.Student" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="cn.school.service.StudentService" %><%--
  Created by IntelliJ IDEA.
  User: ghost
  Date: 2019/12/8
  Time: 22:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%!
    public Date setDate(String date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
%>
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    int id = Integer.parseInt(request.getParameter("id"));
    String sname = request.getParameter("sname");
    String sex = request.getParameter("sex");
    String telephone = request.getParameter("telephone");
    String qq = request.getParameter("qq");
    String wechat = request.getParameter("wechat");
    String gradeid = request.getParameter("gradeid");
    String fromcity = request.getParameter("fromcity");
    String birthday = request.getParameter("birthday");
    String address = request.getParameter("address");
    String pass = request.getParameter("pass");
    Student student = new Student();
    student.setStuno(id);
    student.setSname(sname);
    student.setSex(sex);
    student.setTelephone(telephone);
    student.setQq(qq);
    student.setWechat(wechat);
    student.setGradeid(Long.parseLong(gradeid));
    student.setFromcity(fromcity);
    student.setBirthday(setDate(birthday));
    student.setAddress(address);
    student.setPass(pass);
    out.print(student.toString());
    StudentService ss = new StudentService();
    if(ss.update(student) == 1){
        out.print("<script>alert('更新成功！');" +
                "window.location.href='studentinfo.jsp';</script>");
    }else{
        out.print("<script>alert('更新失败！');" +
                "window.location.href='alterStudent.jsp?id="+id+"';</script>");
    }
%>
</body>
</html>